Skip to content

Conversation

mjnaderi
Copy link

@mjnaderi mjnaderi commented Dec 9, 2016

We found a bug in our project, and after investigating, we found where it comes from. So I created a failing test based on our issue.

In this test, removing prefetch_related from this line:

my_teams = Team.objects.filter(user_profiles=user_c).prefetch_related('user_profiles').distinct()

or removing this "for" loop:

for _ in my_teams:
    pass

resolves the issue, and test passes. But with both of them, test fails.

@mjnaderi
Copy link
Author

mjnaderi commented Dec 9, 2016

Another note:
The behavior is different with Sqlite and PostgreSql.

With Sqlite, the test fails with:

Traceback (most recent call last):
  File "/home/naderi/Repos/django-polymorphic/polymorphic/tests.py", line 1379, in test_unknown_issue
    self.assertEqual(len(my_teams[0].user_profiles.all()), 3)
AssertionError: 4 != 3

With PostgreSql, the test fails with:

Traceback (most recent call last):
  File "/home/naderi/Repos/django-polymorphic/polymorphic/tests.py", line 1379, in test_unknown_issue
    self.assertEqual(len(my_teams[0].user_profiles.all()), 3)
AssertionError: 2 != 3

@mjnaderi
Copy link
Author

mjnaderi commented Dec 9, 2016

Now I found issue #68 and pull request #250. Maybe this issue is related to them.


print(my_teams[0].user_profiles.all())
print(my_teams[1].user_profiles.all())
self.assertEqual(len(my_teams[0].user_profiles.all()), 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right; you're not ordering you QuerySet, so the first result returned by the DB might be team2. It'll probably fail, occasionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants